from spider_modular_main import*
from barChart_flow_workday_weekend_timeline import*
from barChart_flow_workday_weekend_1year import*
from calendar_flow import*
from boxplot_flow_years import*
from lineChart_flow_timeline import*
from lineChart_temp_1year import*
from barChart_flow_month_timeline import*
from barChart_flow_month_1year import*
from lineChart_flow_all import*
from wordCloud_weather_all import*
from lineChart_flow_1year import*
from doughnut_and_RoseDiagram_weather_1year import*
from doughnut_and_RoseDiagram_weather_timeline import*
from lineChart_temp_timeline import*
from draft_1year import*

import random


import sys
sys.path.append(r"C:\Users\LLL\Desktop\大三下学习资料\A综合实验课程\项目进度\1.13-代码汇总\ourCode2.0\Prediction Graphed")
from prediction_main import*
import time
import threading


class Main_all():
    
    def __init__(self, place=0):
        
        self.place=place
        self.tag = 0
        
        #主程序入口
        self.main()
    
    
    def main(self):
        
        self.spider() #爬虫    
        self.paint() #绘图
        self.predict() #预测客流
        
    #打印等待提示消息ljl
    def printMessage(self):
        while self.tag==0:
            print(".",end='')
            time.sleep(0.5)

    def spider(self):
        
        if self.place==0:
            outputFilename="dataset/dataset_jiuzhaigou.csv"
        else:
            outputFilename="dataset/dataset_siguniangshan.csv"
            
        print("不要着急哦，数据正在爬取中~\n请稍后.",end='')#ljl
        self.tag=0
        spiderMsg=threading.Thread(target=self.printMessage)#实现多线程提醒。ljl
        spiderMsg.start()#启动线程ljl
        dataset=spider_modular_main(outputFilename=outputFilename, place=self.place).outputData #获取数据集
        self.tag=1
        print("爬虫模块已运行完毕。")#ljl

    
    def paint(self):
             
        if self.place==0:
            years=range(2013,2017)
            df=pd.read_csv('dataset/data_jiuzhaigou.csv')
        else:
            years=range(2016,2020)
            df=pd.read_csv('dataset/data_siguniangshan.csv')
        

        for year in years:
            Doughnut_and_RoseDiagram_weather_1year(dataset=df, place=self.place, year=str(year)) #绘制某年天气数据圆环图和玫瑰图
            LineChart_flow_1year(dataset=df, place=self.place, year=str(year)) #绘制某年单日客流量折线图
            Calendar_flow(dataset=df, place=self.place, year=str(year)) #绘制某一年的客流日历图 
            BarChart_flow_workday_weekend_1year(dataset=df, place=self.place, year=str(year)) #绘制某年每月工作日与双休日平均客流数条形图
            BarChart_flow_month_1year(dataset=df, place=self.place, year=str(year)) #绘制某年月平均客流条形图
            LineChart_temp_1year(dataset=df, place=self.place, year=str(year)) #绘制某年气温变化折线图
            Draft_1year(dataset=df, place=self.place, year=str(year))
            
        LineChart_flow_all(dataset=df, place=self.place) #绘制近四年客流量折线图（不含时间轴）        
        LineChart_flow_timeline(dataset=df, place=self.place) #绘制近四年客流折线图（含时间轴）
        LineChart_temp_timeline(dataset=df, place=self.place) #绘制近四年气温变化折线图
        Doughnut_and_RoseDiagram_weather_timeline(dataset=df, place=self.place) #绘制近四年天气数据圆环图和玫瑰图（含时间轴）
        WordCloud_weather_all(dataset=df,place=self.place) #绘制近四年天气词云图
        Boxplot_flow_years(dataset=df, place=self.place) #绘制四年的客流箱线图
        BarChart_flow_month_timeline(dataset=df, place=self.place) #绘制近四年月平均客流条形图（含时间轴）
        BarChart_flow_workday_weekend_timeline(dataset=df, place=self.place) #绘制四年每月工作日与双休日平均客流数条形图（含时间轴）

    

    def predict(self):
        #异常处理:预测异常
        try:
            Prediction_main(place=self.place)
        except  :
            pass


# Main_all(place=0)#对九寨沟进行全面数据分析（爬取数据+数据处理+数据存储+数据分析+数据可视化）
# Main_all(place=1)#对四姑娘山进行全面数据分析（爬取数据+数据处理+数据存储+数据分析+数据可视化）